home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / serial / callback.001 / callback~ / callback / lib / dbase / fgetline.c < prev    next >
C/C++ Source or Header  |  1996-07-21  |  798b  |  38 lines

  1.  
  2. #include "dbase.p"
  3.  
  4. char *fgetline(FILE *inf)
  5. {
  6.     static char
  7.         buf [500];                /* input buffer */
  8.     register char
  9.         *cp;
  10.         
  11.     while (1)
  12.     {
  13.         fgets(buf, 499, inf);            /* try to read line */
  14.         
  15.         if (feof(inf))                /* return failure when */
  16.            return (NULL);            /* at EOF */
  17.            
  18.         if (buf[0] == '#')            /* ignore lines starting */
  19.             continue;                /* with hashmark */
  20.            
  21.         cp = buf + strlen(buf) - 1;        /* strip whitespace at end */
  22.         while (isspace(*cp) && cp > buf)
  23.         {
  24.             *cp = '\0';
  25.             cp--;
  26.         }
  27.         
  28.         if (cp == buf)                /* ignore empty lines */
  29.             continue;
  30.         
  31.         cp = buf;                /* skip leading spaces */
  32.         while (isspace(*cp))
  33.             cp++;
  34.             
  35.         return (cp);                /* return that position */
  36.     }
  37. }
  38.